package poker

import "github.com/heroiclabs/nakama-common/runtime"

type RoundAction int64
type PlayerStatus int64

const (
	ActionNone       RoundAction = 0
	ActionCall       RoundAction = 1
	ActionCheck      RoundAction = 2
	ActionRaise      RoundAction = 3
	ActionBet        RoundAction = 4
	ActionAllIn      RoundAction = 5
	ActionFold       RoundAction = 6
	ActionSmallBlind RoundAction = 7
	ActionBigBlind   RoundAction = 8
)

const (
	PlayerStatusIdle    PlayerStatus = 0 // 等待操作
	PlayerStatusPlaying PlayerStatus = 1 // 正在参与中
	PlayerStatusAllIn   PlayerStatus = 2 // 已经Allin了
	PlayerStatusFolded  PlayerStatus = 3 // 已经弃牌了
)

type Player struct {
	runtime.Presence `json:"-"`
	UserID           string `json:"uid"`
	Username         string `json:"username"`
	PlayerGameStatus
	Hand []Card `json:"-"`
}

func NewPlayer(p runtime.Presence) *Player {
	return &Player{
		Presence: p,
		UserID:   p.GetUserId(),
		Username: p.GetUsername(),
	}
}

type PlayerGameStatus struct {
	Seated bool         `json:"seated"` // 是否入座
	Seat   int64        `json:"seat"`   // 当前位置
	Chips  int64        `json:"chips"`  // 剩余筹码
	Bet    int64        `json:"bet"`    // 本轮已下注数量
	Action RoundAction  `json:"action"` // 当前动作
	Status PlayerStatus `json:"status"` // 状态
}

type PublicPlayerView struct {
	UserID   string       `json:"userID"`
	Username string       `json:"username"`
	Avatar   string       `json:"avatar"`
	Seated   bool         `json:"seated"`
	Seat     int64        `json:"seat"`
	Chips    int64        `json:"chips"`
	Bet      int64        `json:"bet"` // 本轮已下注数量
	Action   RoundAction  `json:"action"`
	Status   PlayerStatus `json:"status"`
}

func (p *Player) ToPublicView() PublicPlayerView {
	return PublicPlayerView{
		UserID:   p.GetUserId(),
		Username: p.GetUsername(),
		Avatar:   "",
		Seated:   p.Seated,
		Seat:     p.Seat,
		Chips:    p.Chips,
		Bet:      p.Bet,
		Action:   p.Action,
		Status:   p.Status,
	}
}
